<template>
  <a-modal :open="open" width="560px" title="签到" destroy-on-close centered :footer="null" ok-text="保存" @cancel="onCancel">
    <div class="flex justify-between font-bold border-solid border border-inherit rounded px-2 py-2">
      <div class="flex justify-between w-28">
        <span>{{ patientInfo.brName }}</span>
        <div>
          <span class="mr-1">{{ patientInfo.brSex }}</span>
          <span>{{ patientInfo.brAge }}岁</span>
        </div>
      </div>
      <div>手机号:{{ patientInfo.brMob }}</div>
      <div>卡号:{{ patientInfo.brBlkh }}</div>
    </div>
    <div class="flex justify-between flex-wrap">
      <div class="w-1/3 mt-4">
        <LabelValue label-class="text-right" label="科室" value-class="font-bold" :value="patientInfo.ksmc" />
      </div>
      <div class="w-1/3 mt-4">
        <LabelValue label-class="text-right" label="类别" value-class="font-bold" :value="patientInfo.ghlb" />
      </div>
      <div class="w-1/3 mt-4">
        <LabelValue label-class="text-right" label="医生" value-class="font-bold" :value="patientInfo.empName" />
      </div>
      <div class="w-1/3 mt-4">
        <LabelValue label-class="text-right" label="排队号" value-class="font-bold" :value="patientInfo.queueNo" />
      </div>
    </div>
    <div class="w-full flex justify-center mt-6">
      <a-button type="primary" @click="onOk">签到</a-button>
    </div>
  </a-modal>
</template>
<script setup>
import { ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import { post } from '@/utils/request'

const emit = defineEmits(['update:open', 'update:value', 'success'])
const props = defineProps({
  open: {
    type: Boolean,
    default: false
  },
  rowData: {
    type: Object,
    default: () => ({})
  },
  title: {
    type: String,
    default: ''
  }
})
const patientInfo = ref({})
watch(
  () => props.open,
  (val) => {
    if (val) {
      if (props.rowData?.brId !== '') {
        getPatientInfo()
      } else {
        patientInfo.value = {}
      }
    }
  }
)

const onOk = async () => {
  const res = await post('/outp/nurseQueue/doAddQueue', {
    ...patientInfo.value
  })
  if (res.code !== 0) return message.error(res.msg || '请求失败')
  emit('success')
  onCancel()
}
const getPatientInfo = async () => {
  const { code, data, msg } = await post('/outp/nurseQueue/getBrRegionInfo', {
    brId: props.rowData.brId,
    keyCode: props.rowData?.keyCode,
    qmQrId: props.rowData?.id
  })
  if (code !== 0) return message.error(msg || '请求失败')
  patientInfo.value = data || {}
}

const onCancel = () => {
  emit('update:open', false)
}
</script>
<style lang="less" scoped></style>
